//
//  ClosureTwoVC.swift
//  ReviewSwift
//
//  Created by ladystyle100 on 2017/8/25.
//  Copyright © 2017年 WangXQ. All rights reserved.
//

import UIKit

// 别名一个闭包
typealias ClosureTwoBlock = (Int) -> Int

class ClosureTwoVC: UIViewController {
    
    // 声明一个闭包
    var closure: ClosureTwoBlock?

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        let btn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: self.view.bounds.width, height: 44))
        btn.center = self.view.center
        btn.backgroundColor = UIColor.orange
        btn.setTitle("调用闭包", for: .normal)
        btn.addTarget(self, action: #selector(responds(_:)), for: .touchUpInside)
        self.view.addSubview(btn)
    }
    
    @objc private func responds(_ sender: UIButton) {
        // 解包
        if let a = self.closure {
            // 打印返回的值
            print(a(50))
        }
    }
}












